package com.isnmp.nms.framework.discover.service;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import com.isnmp.common.base.MyException;
import com.isnmp.common.snmp.SNMPFactory;
import com.isnmp.common.snmp.SNMPTarget;
import com.isnmp.common.snmp.mib.MibIPRouterEntry;
import com.isnmp.nms.framework.discover.DeviceInfo;
import com.isnmp.nms.framework.discover.DeviceTypeInfo;
import com.isnmp.nms.framework.discover.SubNetInfo;

public class SearchRouterInfoService {
    private List<SubNetInfo> searchSubNet(SNMPTarget paramSNMPTarget) throws MyException {
        Vector localVector = new Vector();
        try {
            List localList = SNMPFactory.getSNMPAPI().getAllTableData(MibIPRouterEntry.class, paramSNMPTarget);
            Iterator localIterator = localList.iterator();
            while (localIterator.hasNext()) {
                MibIPRouterEntry localMibIPRouterEntry = (MibIPRouterEntry) localIterator.next();
                String str = localMibIPRouterEntry.getIpRouteDest();
                if ((str.endsWith(".0")) && (!str.startsWith("127.")) && (!str.startsWith("224.")) && (!str.equalsIgnoreCase("0.0.0.0")) && (localMibIPRouterEntry.getIpRouteType() == 3)) {
                    SubNetInfo localSubNetInfo = new SubNetInfo();
                    localSubNetInfo.setNetInfo(str);
                    localSubNetInfo.setNetRouterIP(localMibIPRouterEntry.getIpRouteNextHop());
                }
            }
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        return localVector;
    }

    public List<DeviceInfo> searchDeviceByRouterNet(String paramString, List<SNMPTarget> paramList, boolean paramBoolean) {
        Vector localVector = new Vector();
        List localList1 = new SearchNodeService().searchDevice(paramString, paramList, paramBoolean);
        Iterator localIterator1 = localList1.iterator();
        while (localIterator1.hasNext()) {
            DeviceInfo localDeviceInfo = (DeviceInfo) localIterator1.next();
            if (localDeviceInfo.getDeviceType().equalsLogicType(DeviceTypeInfo.RouterType)) {
                SNMPTarget localSNMPTarget = localDeviceInfo.getSnmpTarget();
                try {
                    List localList2 = searchSubNet(localSNMPTarget);
                    Iterator localIterator2 = localList2.iterator();
                    while (localIterator2.hasNext()) {
                        SubNetInfo localSubNetInfo = (SubNetInfo) localIterator2.next();
                        String str = localSubNetInfo.getNetInfo();
                        if (!str.equalsIgnoreCase(paramString)) {
                            List localList3 = new SearchNodeService().searchDevice(str, paramList, paramBoolean);
                            localVector.addAll(localList3);
                        }
                    }
                } catch (Exception localException) {
                    localException.printStackTrace();
                }
            }
        }
        return localVector;
    }
}